var app = getApp();
import * as echarts from '../../ec-canvas/echarts';
// 图表选项

var chart;
// 图表初始化
function initChart(canvas, width, height, dpr) {
  chart = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr, // 像素
  });
  canvas.setChart(chart);
  var option = {
    color: ["#4A52F6", "#1BBC91", "#FF528A","#FF6430"],

    title: {
      text: 0,
      subtext: '今日收益',
      x: 'center',
      y: '40%'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b} : {c} ({d}%)',
    },
    legend: {
      orient: 'horizontal',
      x: 'center',
      y: 'bottom',
      padding: 5,
      data: ['线上支付', '饭票支付', '线下微信', '吧台支付']
    },

    series: [
      {
        type: 'pie',
        radius: ['40%', '55%'],
        center: ['50%', '45%'],

        label: {
          formatter: '{b} \n {d}%',
          "textStyle": {
            "fontSize": 12,
            lineHeight: 22,
            color: '#6D768A',
          },

          rich: {
            a: {
              color: '#999',
              lineHeight: 22,
              align: 'center'
            },
            hr: {
              borderColor: '#aaa',
              width: '100%',
              borderWidth: 0.5,
              height: 0
            },
            b: {
              fontSize: 16,
              lineHeight: 33
            },
            per: {
              color: '#eee',
              backgroundColor: '#334455',
              padding: [2, 4],
              borderRadius: 2
            }
          }
        },
        data: [
          { value: 0, name: '线上支付' },
          { value: 0, name: '饭票支付' },
          { value: 0, name: '线下微信' },
          { value: 0, name: '吧台支付' },
        ],
        itemStyle: {
          // 阴影
          emphasis: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)',
          },
        },
      },
    ],
  };
  chart.setOption(option);
  return chart;
}

var chart2;
// 图表初始化
function initChart2(canvas, width, height, dpr) {
  chart2 = echarts.init(canvas, null, {
    width: width,
    height: height,
    devicePixelRatio: dpr, // 像素
  });
  canvas.setChart(chart2);
  var option2 = {
    color: ["#4A52F6", "#1BBC91", "#FF528A","#FF6430"],

    title: {
      text: 0,
      subtext: '今日收益',
      x: 'center',
      y: '40%'
    },
    tooltip: {
      trigger: 'item',
      formatter: '{b} : {c} ({d}%)',
    },
    legend: {
      orient: 'horizontal',
      x: 'center',
      y: 'bottom',
      padding: 5,
      data: ['线上支付', '饭票支付', '线下微信', '吧台支付']
    },

    series: [
      {
        type: 'pie',
        radius: ['40%', '55%'],
        center: ['50%', '45%'],

        label: {
          formatter: '{b} \n {d}%',
          "textStyle": {
            "fontSize": 12,
            lineHeight: 22,
            color: '#6D768A',
          },

          rich: {
            a: {
              color: '#999',
              lineHeight: 22,
              align: 'center'
            },
            hr: {
              borderColor: '#aaa',
              width: '100%',
              borderWidth: 0.5,
              height: 0
            },
            b: {
              fontSize: 16,
              lineHeight: 33
            },
            per: {
              color: '#eee',
              backgroundColor: '#334455',
              padding: [2, 4],
              borderRadius: 2
            }
          }
        },
        data: [
          { value: 0, name: '线上支付' },
          { value: 0, name: '饭票支付' },
          { value: 0, name: '线下微信' },
          { value: 0, name: '吧台支付' },
        ],
        itemStyle: {
          // 阴影
          emphasis: {
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)',
          },
        },
      },
    ],
  };
  chart2.setOption(option2);
  return chart2;
}

Page({
  /**
   * 页面的初始数据
   */
  data: {
    ec: {
      onInit: initChart,
    },
    ecs: {
      onInit: initChart2,
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var store_id = wx.getStorageSync("store_id");
    console.log(store_id)
    if(!store_id){
      app.showToast("请登录小程序")
      wx.navigateBack();
    }else{
      this.setData({
        store_id:wx.getStorageSync("store_id")
      })

      this.getProfitSituation();

    }
  },

  getProfitSituation:function(){
    var t = this;
    app.visit("account/getProfitSituation", {
      store_id:t.data.store_id
    }, "", function(c) {
      console.log(c)
      if(0 == c.code){
        var option = {
          color: ["#4A52F6", "#1BBC91", "#FF528A","#FF6430","#FF658A","#E7A9F6","#B8FF21"],
          title: {
            text: c.data.zong_price,
            subtext: '今日收益',
            x: 'center',
            y: '40%'
          },
          tooltip: {
            trigger: 'item',
            formatter: '{b} : {c} ({d}%)',
          },
          legend: {
            orient: 'horizontal',
            x: 'center',
            y: 'bottom',
            padding: 5,
            data: ['线上支付','饭票支付','余额支付','红包支付','线下微信','线下吧台','线下余额']
          },
          series: [
            {
              type: 'pie',
              radius: ['40%', '55%'],
              center: ['50%', '45%'],

              label: {
                formatter: '{b} \n {d}%',
                "textStyle": {
                  "fontSize": 12,
                  lineHeight: 22,
                  color: '#6D768A',
                },

                rich: {
                  a: {
                    color: '#999',
                    lineHeight: 22,
                    align: 'center'
                  },
                  hr: {
                    borderColor: '#aaa',
                    width: '100%',
                    borderWidth: 0.5,
                    height: 0
                  },
                  b: {
                    fontSize: 16,
                    lineHeight: 33
                  },
                  per: {
                    color: '#eee',
                    backgroundColor: '#334455',
                    padding: [2, 4],
                    borderRadius: 2
                  }
                }
              },
              data: [
                { value: c.data.xs.wxzf_price, name: '线上支付' },
                { value: c.data.xs.fpzf_price, name: '饭票支付' },
                { value: c.data.xs.yezf_price, name: '余额支付' },
                { value: c.data.xs.hbzf_price, name: '红包支付' },
                { value: c.data.sm.wxzf_price, name: '线下微信' },
                { value: c.data.sm.btzf_price, name: '线下吧台' },
                { value: c.data.sm.xxyezf_price, name: '线下余额' },
              ],
              itemStyle: {
                // 阴影
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
              },
            },
          ],
        };
        setTimeout(()=>{
          chart.clear()
          chart.setOption(option);
        },100)
        var option2 = {
          color: ["#4A52F6", "#1BBC91", "#FF528A","#FF6430","#FF658A","#E7A9F6","#B8FF21"],
          title: {
            text: c.data.zong_num,
            subtext: '今日笔数',
            x: 'center',
            y: '40%'
          },
          tooltip: {
            trigger: 'item',
            formatter: '{b} : {c} ({d}%)',
          },
          legend: {
            orient: 'horizontal',
            x: 'center',
            y: 'bottom',
            padding: 5,
            data: ['线上支付','饭票支付','余额支付','红包支付','线下微信','线下吧台','线下余额']
          },
          series: [
            {
              type: 'pie',
              radius: ['40%', '55%'],
              center: ['50%', '45%'],

              label: {
                formatter: '{b} \n {d}%',
                "textStyle": {
                  "fontSize": 12,
                  lineHeight: 22,
                  color: '#6D768A',
                },

                rich: {
                  a: {
                    color: '#999',
                    lineHeight: 22,
                    align: 'center'
                  },
                  hr: {
                    borderColor: '#aaa',
                    width: '100%',
                    borderWidth: 0.5,
                    height: 0
                  },
                  b: {
                    fontSize: 16,
                    lineHeight: 33
                  },
                  per: {
                    color: '#eee',
                    backgroundColor: '#334455',
                    padding: [2, 4],
                    borderRadius: 2
                  }
                }
              },
              data: [
                { value: c.data.xs.wxzf_num, name: '线上支付' },
                { value: c.data.xs.fpzf_num, name: '饭票支付' },
                { value: c.data.xs.yezf_num, name: '余额支付' },
                { value: c.data.xs.hbzf_num, name: '红包支付' },
                { value: c.data.sm.wxzf_num, name: '线下微信' },
                { value: c.data.sm.btzf_num, name: '线下吧台' },
                { value: c.data.sm.xxyezf_num, name: '线下余额' },
              ],
              itemStyle: {
                // 阴影
                emphasis: {
                  shadowBlur: 10,
                  shadowOffsetX: 0,
                  shadowColor: 'rgba(0, 0, 0, 0.5)',
                },
              },
            },
          ],
        };
        setTimeout(()=>{
          chart2.clear()
          chart2.setOption(option2);
        },100)
      }else{
        app.showToast(c.msg)
      }
    })
  },

});
